const state = {
	deviceInfo: {
		ostype: "",
		imei: "",
		uuid: "",
		vendor: "",
		model: "",
		token: "",
		clientid: "",
		ua: "",
		version: "",
		osversion: ""
	}
}

const mutations = {
	SET_DEVICE: (state, deviceInfo) => {
		Object.assign(state.deviceInfo, deviceInfo);
	}
}

const actions = {
	// set deviceinfo
	setDeviceInfo({commit}) {
		return new Promise((resolve,reject) => {
			uni.getSystemInfo({
				success: function(res) {
					let temp = {
						ostype: res.platform, //客户端平台，值域为：ios、android
						imei: "",
						uuid: "",
						vendor: "",
						model: res.model,
						token: "",
						clientid: "",
						ua: "",
						version: res.version,
						osversion: ""
					};
					commit('SET_DEVICE', temp);
					resolve(res);
				},
				fail:function(err){
					reject(err);
				}
			});
			
		})
	},
	//clear deviceinfo
	clearDeviceInfo({commit}) {
		return new Promise(resolve => {
			commit('SET_DEVICE', {});
			resolve()
		})
	}

}

export default {
	namespaced: true,
	state,
	mutations,
	actions
}
